package com.googlecode.maratische.google.gui;

import static com.googlecode.maratische.google.MainController.getMainController;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import org.apache.log4j.Logger;

import com.googlecode.maratische.google.model.Feed;

public class InfWindowCheckNewFeeds extends InfWindowAddOfflineMode  {
	static Logger logger = Logger.getLogger(InfWindowCheckNewFeeds.class.getName());
	List<Feed> newFeeds = null;
	
	public InfWindowCheckNewFeeds(List<Feed> newFeeds,Point parentPosition, Dimension parentSize) {
		super(parentPosition, parentSize);
		this.newFeeds = newFeeds;
		init();
		initButtons();
	}

	@Override
	public void init() {
		
		setLayout(new FlowLayout());
		StringBuilder name = new StringBuilder("<html>");
		name.append(getBundleMessage("infwindow.checknewfeeds.question.1"));
		if (newFeeds!= null) {
			name.append(" ").append(newFeeds.size()).append(" ");
		}
		name.append(getBundleMessage("infwindow.checknewfeeds.question.2"));
		name.append("</html>");
		JLabel label = new JLabel(name.toString());
		label.setToolTipText(name.toString());
		add(label);
		
		
	}

	protected void initButtons() {
		JButton buttonYes = new JButton(getBundleMessage("button.yes"));
		buttonYes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				buttonYesAction();
			}
		});
		buttonCancel = new JButton(getBundleMessage("button.no"));
		buttonCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				getMainController().changeOfflineSupportForSelectedFeed(false);
				close();
			}
		});
		add(buttonYes);
		add(buttonCancel);
		
		timer.start();
	}
	
	
	@Override
	protected void buttonYesAction() {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				getMainController().showWindowTreeAddNewFeeds();
			}
		});
		close();
	}
	
	@Override
	protected void buttonNoAction() {
		close();
	}
	
	private static final long serialVersionUID = 4732767937470858869L;

}
